#pragma once
#include <vector>
#include <string>

//#include "autoerconstant.hxx"

#if defined(WIN32)
#ifdef EXPORT
#undef EXPORT
#endif
#if defined(AUTO_EXPORTS)
/* DLL export */
#define EXPORT __declspec(dllexport)
#else
/* EXE import */
#define EXPORT __declspec(dllimport)
//#define EXPORT
#endif
#else
#define EXPORT 
#endif

using namespace std;

class TcpClientSocket;
class BridgeConn;
class TaskManager;
class RobotManager;
class DB;
class GisusDB;
class Task;
class User;
class FileLog;

typedef void(*DMFun)(std::string,int);

class EXPORT Auto
{
public:
	//
	typedef int ModeKind;
	static const ModeKind Normal =	1 << 0;
	static const ModeKind PQFirst =	1 << 1;

public:
	Auto(DMFun f=0);
	~Auto();

	int Login(const string& username, const string& pwd);
	void Start(void);
	void Shutdown(void);

	/* use in pair for user to input Captcha. */
	const char* GetCaptcha(size_t& size, bool& urgent);
	bool SetCaptcha(const string& captcha);

	/* task related methods. */
	int SaveTask(Task* task);

	void SetQueryVL(int interval);
	void SetMode(ModeKind mode);
	void DisplayMsg(string msg, int msgType);

	void StartQuery(bool start = true);

	/* Task browse */
	Task* GetTaskByCjh(const string& cjh);
	Task* GetNeighbor(int curTaskId, bool next=true);

	const Task* SetPTask(const string& cjh);
	bool ResetPTask(const string& cjh);
	bool RestoreBEndData(void);

	const User* GetUser(void) const {return user;}

private:
	const User* user;
	TaskManager* taskManager;
	RobotManager* robotManager;
	DB* db;
	GisusDB* gisusdb;

	BridgeConn* bridgeConn;

	DMFun dmFun;

	FileLog* _filelog;
};